package com.easy.dev.utils;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class ClassNameUtils {

    private static Map<String, String> cache = new HashMap<String, String>();

    public static String getUnderlineTableName(String name) {
        String n = cache.get(name);
        if (StringUtils.isEmpty(n)) {
            StringBuilder sb = new StringBuilder(20);
            char[] cs = name.toCharArray();
            sb.append(Character.toLowerCase(cs[0]));
            for(int i=1;i< cs.length;i++){
                char c = cs[i];
                if (Character.isUpperCase(c)) {
                    sb.append("_").append(Character.toLowerCase(c));
                } else {
                    sb.append(c);
                }
            }
            return sb.toString();
        }
        return n;
    }

}
